import Vue from "vue";
import Router from "vue-router";
import HelloWorld from "@/components/HelloWorld";
import AnotherPage from "@/components/AnotherPage";
import MainRouter from "@/components/MainRouter";
Vue.use(Router);

const isQiankun = window.__POWERED_BY_QIANKUN__;
const base = "/a/c/vuemicro";
const router = [
  {
    path: "/",
    name: "MainRouter",
    component: MainRouter,
    children: [
      {
        path: "/HelloWorld",
        name: "HelloWorld",
        component: HelloWorld
      },
      {
        path: "/AnotherPage",
        name: "AnotherPage",
        component: AnotherPage
      }
    ]
  }
];

const changeRouterBase = (router, isQiankun) => {
  return router.map(item => {
    item.path = isQiankun ? `${base}${item.path}` : item.path;
    if (item.children.length) changeRouterBase(item.children);
    return item;
  });
};
export default changeRouterBase(router,isQiankun);
